function depthFirst1(obj) {
	// 深度优先，递归法
	if(typeof obj !== 'object' || !obj){
		return obj;
	}
	
	let result = [];
	for(let key in obj){
		result.push(obj[key]);
		let children = obj[key].children;
		if(children){
			result.push(...depthFirst(children))
		}
	}
	
	return result;
}
function depthFirst2(obj) {
	// 深度优先，模拟栈
	if(typeof obj !== 'object' || !obj){
		return obj;
	}
	
	let result = [];
	let stack = [obj];
	
	while(stack.length){
		let item = stack.pop();
		result.push(item);
		let children = item.children || [];
		for(let i = (children.length-1); i>=0;i--){
			stack.push(children[i])
		}
	}
	
	return result;
}
const obj = {
	id: 0,
	children: [
	{
		id: 1,
		children:[
			{
				id: 2,
				children:[
					{
						id: 3,
					}
				]
			},
			{
				id: 4,
				children:[
					{
						id: 5,
					}
				]
			},
			{
				id: 6,
				children:[
					{
						id: 7,
					}
				]
			},
			{
				id: 8
			},
			{
				id: 9
			},
			{
				id: 10
			}
		]
	},
	{
		id: 11,
		children:[
			{
				id: 12,
				children:[
					{
						id: 13,
					}
				]
			},
			{
				id: 14,
				children:[
					{
						id: 15,
					}
				]
			},
			{
				id: 16,
				children:[
					{
						id: 17,
					}
				]
			}
		]
	}
]
};


function breadthFirst1(obj) {
	// 广度优先，模拟堆
	if(typeof obj !== 'object' || !obj){
		throw new Error('参数必须时objec类型');
	}
	let result = [];
	let stack = [obj];
	while(stack.length){
		let item = stack.shift();
		result.push(item);
		let children = item.children || [];
		for(let i = 0;i<children.length;i++){
			stack.push(children[i]);
		}
	}
	return result;
}
function breadthFirst2(obj) {
	// 广度优先，递归法
	if(typeof obj !== 'object' || !obj){
		throw new Error('参数必须时objec类型');
	}
	let result = [];
	
	let item = obj.children;
	if(item){
		result.push(obj);
		result.push(...breadthFirst(item));
	}else{
		for(let i in obj){
			result.push(obj[i]);
		}
		for(let i in result){
			if(result[i].children){
				result.push(...breadthFirst(result[i].children));
			}
		}
	}

	return result;
}

function depthFirstDeepCopy1(obj) {
	// 深度优先实现深拷贝，递归法
	let result= obj.length ? [] : {};
	
	
	if(typeof obj === 'object' && obj){
		for(let key in obj){
			result[key] = depthFirstDeepCopy1(obj[key]);
		}
	}else{
		return obj;
	}
	return result;
}
function breadthFirst1DeepCopy1(obj) {
	// 广度优先实现深拷贝，模拟堆
	let result ={};
	let dataStack = [obj];
	let indexStack =[result];
	
	while(dataStack.length){
		let dataItem = dataStack.shift();
		let indexItem = indexStack.shift();
		
		for(let key in dataItem){
			if(key === 'id') consoleg.log(dataItem[key]);
			if(typeof dataItem[key] === 'object'){
				dataStack.push(dataItem[key]);
				indexItem[key] = dataItem[key].length ? [] : {};
				indexStack.push(indexItem[key]);
			}else{
				indexItem[key] = dataItem[key];
			}
		}
	}
	
	return result;
}
console.log(depthFirstDeepCopy2(obj))